/**
 * 
 */
package evolution;

import java.util.ArrayList;

/**
 * @author vtkhanh
 * 
 */
public class Individual {
    private ArrayList<Gene> mGenes;    

    public Individual() {
	this.mGenes = new ArrayList<Gene>();
    }

    public Individual(Individual individual) {
	this.mGenes = new ArrayList<Gene>();
	for (Gene g : individual.getGenes()) {
	    Gene newGene = new Gene(g);
	    this.mGenes.add(newGene);
	}
    }

    public ArrayList<Gene> getGenes() {
	return mGenes;
    }

    public void setGenes(ArrayList<Gene> genes) {
	mGenes = genes;
    }

    public void addGene(Gene gene) {
	mGenes.add(gene);
    }

    public int getCost() {
	int cost = 0;
	for (Gene gene : mGenes) {
	    cost += gene.getCost();
	}
	return cost;
    }   

    public Gene getGene(int geneId) {
	for (Gene gene : mGenes) {
	    if (gene.getGeneId() == geneId) {
		return gene;
	    }
	}
	return null;
    }

    public void updateGene(Gene gene) {
	for (Gene g : mGenes) {
	    if (g.getGeneId() == gene.getGeneId()) {
		g.setRoomId(gene.getRoomId());
		g.setTimeslot(gene.getTimeslot());
		break;
	    }
	}
    }

    public boolean isSame(Individual other) {
	ArrayList<Gene> genes = other.getGenes();
	for (Gene gene : genes) {
	    if (!mGenes.contains(gene)) {
		return false;
	    }
	}
	return true;
    }

}
